#ifndef __TRACELOG_H_CFE73324_3D63_4A09_BF51_D6463F1846A7_INCLUDED__
#define __TRACELOG_H_CFE73324_3D63_4A09_BF51_D6463F1846A7_INCLUDED__

#define XL_LOG_POLICY MyLogPolicy

#include "xlLog.h"
#include <stdarg.h>
#include <string>

class MyLogPolicy
{
public:
    static MyLogPolicy &GetInstance()
    {
        static MyLogPolicy instance;
        return instance;
    }

public:
    void EnterFunction(::xl::LOG_LEVEL logLevel, const wchar_t * /*file*/, const wchar_t *funName, const wchar_t *line)
    {
        fwprintf(stderr, L"%-7s: >>>>>>>>>> Enter %s (L%s)\n", GetLogLevelString(logLevel).c_str(), funName, line);
    }

    void LeaveFunction(::xl::LOG_LEVEL logLevel, const wchar_t * /*file*/, const wchar_t *funName, const wchar_t *line)
    {
        fwprintf(stderr, L"%-7s: <<<<<<<<<< Leave %s (L%s)\n", GetLogLevelString(logLevel).c_str(), funName, line);
    }

    void Print(::xl::LOG_LEVEL logLevel, const wchar_t * /*file*/, const wchar_t * /*funName*/, const wchar_t *line, const wchar_t *format, ...)
    {
        wchar_t prefix[10], postfix[10];
        swprintf(prefix, 10, L"%-7s: ", GetLogLevelString(logLevel).c_str());
        swprintf(postfix, 10, L" (L%s)\n", line);
        std::wstring newFormat = prefix;
        newFormat += format;
        newFormat += postfix;

        va_list args;
        va_start(args, format);
        vfwprintf(stderr, newFormat.c_str(), args);
        va_end(args);
    }

private:
    std::wstring GetLogLevelString(::xl::LOG_LEVEL logLevel)
    {
        switch (logLevel)
        {
        case ::xl::LL_FATAL:
            return L"FATAL";
        case ::xl::LL_ERROR:
            return L"ERROR";
        case ::xl::LL_WARNING:
            return L"WARNING";
        case ::xl::LL_INFO:
            return L"INFO";
        case ::xl::LL_VERBOSE:
            return L"VERBOSE";
        default:
            return L"NOLEVEL";
        }
    }
};


#endif // #ifndef __TRACELOG_H_CFE73324_3D63_4A09_BF51_D6463F1846A7_INCLUDED__
